-
Notifications
You must be signed in to change notification settings - Fork 43
2358-2 #266
base: master
Are you sure you want to change the base?
2358-2 #266
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general it's ok
2358/2/index.rb
Outdated
require 'russian_obscenity' | ||
require 'terminal-table' | ||
|
||
TEXTS_PATH = '/home/dshop/Vova/word/texts'.freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is a bad idea. use Dir.pwd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a VERY bad idea.
2358/2/index.rb
Outdated
|
||
Dir.new(TEXTS_PATH).each do |file| | ||
next if file =~ /^\./ | ||
rapper_name = file.split(/ против | VS | vs /)[0].split.join(' ') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.split.join(' ')
??
2358/2/index.rb
Outdated
next if file =~ /^\./ | ||
rapper_name = file.split(/ против | VS | vs /)[0].split.join(' ') | ||
|
||
name_from_hash = RAPPER_NAMES.find { |_, v| rapper_name =~ v } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'v' is a bad name. how about 'pattern'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check the code below for 'v' and 'k'
2358/2/index.rb
Outdated
bad_words_counter = {} | ||
words_per_battle_counter = {} | ||
words_per_round_counter = {} | ||
average_words_per_round_conter = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean counter?
2358/2/index.rb
Outdated
|
||
RAPPER_NAMES.each do |k, _| | ||
words_per_battle_counter[k] = (bad_words_counter[k].to_f / battles_count[k]).round(2) | ||
average_words_per_round_conter[k] = words_per_round_counter[k] / (battles_count[k] * 3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is 3?
сразу нет из-за названия |
нужно больше больше ООП |
2358/2/index.rb
Outdated
end | ||
end | ||
|
||
def show_table |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/MethodLength: Method has too many lines. [15/10]
2358/2/index.rb
Outdated
|
||
private | ||
|
||
def calculation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/AbcSize: Assignment Branch Condition size for calculation is too high. [40.94/15]
Metrics/CyclomaticComplexity: Cyclomatic complexity for calculation is too high. [7/6]
Metrics/MethodLength: Method has too many lines. [31/10]
Metrics/PerceivedComplexity: Perceived complexity for calculation is too high. [10/7]
2358/2/index.rb
Outdated
|
||
words_from_text = lines.join.tr("\n", ' ').delete('.,;').split | ||
|
||
bad_words_count = words_from_text.select do |x| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UncommunicativeVariableName: TextHandler#calculation has the variable name 'x'. More info.
2358/2/index.rb
Outdated
end | ||
end | ||
|
||
def show_table |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TooManyStatements: TextHandler#show_table has approx 6 statements. More info.
2358/2/index.rb
Outdated
|
||
private | ||
|
||
def calculation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TooManyStatements: TextHandler#calculation has approx 20 statements. More info.
2358/2/index.rb
Outdated
require 'terminal-table' | ||
require_relative 'constants' | ||
|
||
class TextHandler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TooManyInstanceVariables: TextHandler has at least 6 instance variables. More info.
|
||
name_from_hash = RAPPER_NAMES.find { |_, reg| rapper_name =~ reg } | ||
|
||
next if name_from_hash.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NilCheck: TextHandler#calculation performs a nil-check. More info.
next if file =~ /^\./ | ||
rapper_name = file.split(/ против | VS | vs /)[0].split.join(' ') | ||
|
||
name_from_hash = RAPPER_NAMES.find { |_, reg| rapper_name =~ reg } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NestedIterators: TextHandler#calculation contains iterators nested 2 deep. More info.
2358/2/index.rb
Outdated
end | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/EmptyLines: Extra blank line detected.
2358/2/index.rb
Outdated
end | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/EmptyLines: Extra blank line detected.
2358/2/index.rb
Outdated
end | ||
else | ||
puts "Рэпер #{@name} не известен мне. Зато мне известны:" | ||
RAPPER_NAMES.keys.shuffle.first(5).each { |name| puts "#{name}\n" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performance/Sample: Use sample(5) instead of shuffle.first(5).
2358/2/index.rb
Outdated
def show_favorite_word | ||
if RAPPER_NAMES[@name] | ||
counter_array = (@words_counter[@name] - SHORT_WORDS).group_by { |name| name }.map { |name, counter| [name, counter.count] } | ||
list_of_words = Hash[counter_array].sort_by {|_, counter| counter }.reverse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceInsideBlockBraces: Space between { and | missing.
2358/2/index.rb
Outdated
|
||
def show_favorite_word | ||
if RAPPER_NAMES[@name] | ||
counter_array = (@words_counter[@name] - SHORT_WORDS).group_by { |name| name }.map { |name, counter| [name, counter.count] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [130/120]
2358/2/index.rb
Outdated
end | ||
# rubocop:enable Metrics/MethodLength | ||
|
||
def show_favorite_word |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/AbcSize: Assignment Branch Condition size for show_favorite_word is too high. [20.12/15]
# :reek:NilCheck | ||
# :reek:NestedIterators | ||
def calculation | ||
Dir.new(TEXTS_PATH).each do |file| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/BlockLength: Block has too many lines. [30/25]
2358/2/index.rb
Outdated
end | ||
# rubocop:enable Metrics/MethodLength | ||
|
||
def show_favorite_word |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TooManyStatements: TextHandler#show_favorite_word has approx 10 statements. More info.
2358/2/index.rb
Outdated
|
||
def show_result | ||
calculation | ||
if @name.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NilCheck: TextHandler#show_result performs a nil-check. More info.
2358/2/constants.rb
Outdated
@@ -0,0 +1,111 @@ | |||
TEXTS_PATH = "#{Dir.pwd}/texts".freeze | |||
SHORT_WORDS = %w[в на и я с не ни по под от у ты что Я И ТЫ как это Но - тебя но меня он А мне за все бы был кто так же его то Это тебе Ты а про вы мой Он тут Что из есть у здесь нет Как к Если Не там даже Вы для Ты ф про вы мой Он тут Что из у Как к Не там Вы где для В до всё мы или – У То *** раз Вот Мы еще со их Ну о без].freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [335/120]
Layout/SpaceInsideArrayPercentLiteral: Use only a single space inside array percent literal.
2358/2/index.rb
Outdated
) | ||
puts table | ||
end | ||
# rubocop:disable Metrics/LineLength |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/UnneededCopDisableDirective: Unnecessary disabling of Metrics/LineLength.
2358/2/index.rb
Outdated
# rubocop:disable Metrics/MethodLength | ||
# rubocop:disable Metrics/AbcSize | ||
# rubocop:disable Metrics/CyclomaticComplexity | ||
# rubocop:disable Metrics/PerceivedComplexity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/UnneededCopDisableDirective: Unnecessary disabling of Metrics/PerceivedComplexity.
2358/2/index.rb
Outdated
|
||
# rubocop:disable Metrics/MethodLength | ||
# rubocop:disable Metrics/AbcSize | ||
# rubocop:disable Metrics/CyclomaticComplexity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/UnneededCopDisableDirective: Unnecessary disabling of Metrics/CyclomaticComplexity.
2358/2/index.rb
Outdated
private | ||
|
||
# rubocop:disable Metrics/MethodLength | ||
# rubocop:disable Metrics/AbcSize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/UnneededCopDisableDirective: Unnecessary disabling of Metrics/AbcSize.
2358/2/index.rb
Outdated
|
||
private | ||
|
||
# rubocop:disable Metrics/MethodLength |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/UnneededCopDisableDirective: Unnecessary disabling of Metrics/MethodLength.
2358/2/constants.rb
Outdated
# :reek:NilCheck | ||
TEXTS_PATH = "#{Dir.pwd}/texts".freeze | ||
|
||
SHORT_WORDS = %w[в на и я с не ни по под от у ты что Я И ТЫ как это Но - тебя но меня он А мне за все бы был кто так же его то Это тебе Ты а про вы мой Он тут Что из есть у здесь нет Как к Если Не там даже Вы для Ты ф про вы мой Он тут Что из у Как к Не там Вы где для В до всё мы или – У То *** раз Вот Мы еще со их Ну о без].freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [335/120]
Layout/SpaceInsideArrayPercentLiteral: Use only a single space inside array percent literal.
2358/2/index.rb
Outdated
end | ||
else | ||
puts "Рэпер #{@name} не известен мне. Зато мне известны:" | ||
RAPPER_NAMES.keys.shuffle.first(5).each do |name| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performance/Sample: Use sample(5) instead of shuffle.first(5).
2358/2/index.rb
Outdated
# :reek:TooManyStatements | ||
def show_favorite_word | ||
if RAPPER_NAMES[@name] | ||
counter_array = (@words_counter[@name] - SHORT_WORDS).group_by { |name| name }.map { |name, counter| [name, counter.count] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [130/120]
2358/2/index.rb
Outdated
end | ||
|
||
# :reek:TooManyStatements | ||
def show_favorite_word |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/AbcSize: Assignment Branch Condition size for show_favorite_word is too high. [20.12/15]
Metrics/MethodLength: Method has too many lines. [12/10]
2358/2/index.rb
Outdated
puts table | ||
end | ||
|
||
# :reek:TooManyStatements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/CommentIndentation: Incorrect indentation detected (column 1 instead of 2).
2358/2/index.rb
Outdated
end | ||
|
||
# :reek:TooManyStatements | ||
def show_table |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/MethodLength: Method has too many lines. [15/10]
# :reek:TooManyStatements | ||
# :reek:NilCheck | ||
# :reek:NestedIterators | ||
def calculation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/AbcSize: Assignment Branch Condition size for calculation is too high. [43.65/15]
Metrics/CyclomaticComplexity: Cyclomatic complexity for calculation is too high. [8/6]
Metrics/MethodLength: Method has too many lines. [36/10]
Metrics/PerceivedComplexity: Perceived complexity for calculation is too high. [12/7]
2358/2/index.rb
Outdated
@name = name | ||
end | ||
# :reek:NilCheck | ||
def show_result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/EmptyLineBetweenDefs: Use empty lines between method definitions.
2358/2/index.rb
Outdated
@top = top | ||
@name = name | ||
end | ||
# :reek:NilCheck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/CommentIndentation: Incorrect indentation detected (column 0 instead of 2).
2358/2/index.rb
Outdated
end | ||
|
||
# :reek:TooManyStatements | ||
def show_favorite_word |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/AbcSize: Assignment Branch Condition size for show_favorite_word is too high. [19.13/15]
Metrics/MethodLength: Method has too many lines. [12/10]
2358/2/index.rb
Outdated
# rubocop:disable Metrics/AbcSize | ||
# rubocop:disable Layout/CommentIndentation | ||
# :reek:TooManyStatements | ||
def show_favorite_word |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/EmptyLineBetweenDefs: Use empty lines between method definitions.
2358/2/index.rb
Outdated
# rubocop:disable Metrics/MethodLength | ||
# rubocop:disable Metrics/LineLength | ||
# rubocop:disable Metrics/AbcSize | ||
# rubocop:disable Layout/CommentIndentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/UnneededCopDisableDirective: Unnecessary disabling of Layout/CommentIndentation.
2358/2/index.rb
Outdated
) | ||
puts table | ||
end | ||
# rubocop:disable Metrics/MethodLength |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/UnneededCopDisableDirective: Unnecessary disabling of Metrics/MethodLength.
2358/2/index.rb
Outdated
end | ||
# rubocop:enable Layout/EmptyLineBetweenDefs | ||
# rubocop:enable Layout/CommentIndentation | ||
private |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/EmptyLinesAroundAccessModifier: Keep a blank line before and after private.
2358/2/index.rb
Outdated
@top = top | ||
@name = name | ||
end | ||
# rubocop:disable Layout/CommentIndentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/UnneededCopDisableDirective: Unnecessary disabling of Layout/CommentIndentation.
2358/2/index.rb
Outdated
# rubocop:enable Metrics/MethodLength | ||
# rubocop:enable Metrics/LineLength | ||
# rubocop:enable Metrics/AbcSize | ||
# rubocop:enable Layout/CommentIndentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/UnneededCopEnableDirective: Unnecessary enabling of Layout/CommentIndentation.
2358/2/index.rb
Outdated
end | ||
end | ||
# rubocop:enable Layout/EmptyLineBetweenDefs | ||
# rubocop:enable Layout/CommentIndentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/UnneededCopEnableDirective: Unnecessary enabling of Layout/CommentIndentation.
2358/2/index.rb
Outdated
# rubocop:enable Metrics/MethodLength | ||
# rubocop:enable Metrics/LineLength | ||
# rubocop:enable Metrics/AbcSize | ||
# rubocop:enable Layout/CommentIndentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/UnneededCopEnableDirective: Unnecessary enabling of Layout/CommentIndentation.
2358/2/index.rb
Outdated
end | ||
end | ||
# rubocop:enable Layout/EmptyLineBetweenDefs | ||
# rubocop:enable Layout/CommentIndentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/UnneededCopEnableDirective: Unnecessary enabling of Layout/CommentIndentation.
Номер
2358
Номер задания
2
Ссылка на видео с демо
https://youtu.be/U3CgabuJJoE
Комментарии